#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<string>
#include<cmath>
#include<stdlib.h>
#include <set>
using namespace std;
string s;
set <string> result;
void getIP(string temp,int st,int en,int time)//获取IP地址
{
    if(en>s.size())
        return ;
    if(time>3)
        return ;
    string sub=s.substr(st,en-st);
    if(sub[0]=='0'&&sub.size()>1)
        return ;
    int num=atoi(sub.substr(0,en-st).c_str());
    if(num>255)
        return ;
    temp+=sub;
    if(en!=s.size())
        temp+=".";
    else
    {
        if(time==3)
            result.insert(temp);
            return ;
    }
    getIP(temp,en,en+1,time+1);
    getIP(temp,en,en+2,time+1);
    getIP(temp,en,en+3,time+1);
}
void printfIP()//输出结果
{
    if(result.empty())
    {
        printf("输入不合法\n");
    }
    else
    {
        set <string>::iterator a;
        printf("可能有效的IP地址有：\n");
        for(a=result.begin();a!=result.end();a++)
            cout<<*a<<endl;
        result.clear();
    }
    return ;
}
int main()
{
    while(~printf("请输入需要恢复的IP地址：\n"))
    {
        int num;
        cin>>s;
        string temp="";
        getIP(temp,0,1,0);
        getIP(temp,0,2,0);
        getIP(temp,0,3,0);
        printfIP();
        printf("继续请输入1，退出操作请输入0\n");
        cin>>num;
        if(num==0)
            break;
        else
            continue;
    }
    return 0;
}